home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13213 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: ix.netcom.com!news
  2. From: jlilley@ix.netcom.com (John Lilley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: new and multidimensional arrays
  5. Date: 24 Mar 1996 04:13:25 GMT
  6. Organization: Netcom
  7. Message-ID: <4j2i55$j4l@dfw-ixnews4.ix.netcom.com>
  8. References: <4il2rd$4fs@NNTP.MsState.Edu>
  9. NNTP-Posting-Host: den-co25-11.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-NETCOM-Date: Sat Mar 23 10:13:25 PM CST 1996
  13. X-Newsreader: WinVN 0.99.7
  14.  
  15. >if i have a method declared as:
  16. >setValues (int, int, float [][3])
  17. >how can i declare a dynamic array with new?
  18. >
  19. >i tried:
  20. >
  21. >float *variable[3];
  22. >
  23. >for (i=0; i<size; i++)
  24. >    variable [i] = new float [3];
  25. >
  26. >but it doesnt work [the compiler says that there is no instance of
  27. >the above method that accepts that kind of a parameter.
  28.  
  29.  
  30. There are some types that are difficult (impossible) to declare in
  31. one line.  I'd use a typedef, which is more readable.  Or rather,
  32. not unreadable.
  33.  
  34. typedef float float3[3];
  35. setValues (int, int, float3[])
  36.  
  37. void glarp()
  38. {
  39.     float3 *var;
  40.  
  41.     var = new float3[4];
  42.     setValues(1,1,var);
  43. }
  44.  
  45. john lilley
  46.  
  47.